package ncme.auto.framework.core.entities.aspect.parameter;

import ncme.auto.framework.core.entities.ResMsg;
import ncme.auto.framework.core.enums.Order;

import javax.servlet.http.HttpServletRequest;

public class ServiceInfo {

    private Object entity;

    private ParamConverter paramConverter;

    private HttpServletRequest request;

    private Order presentOrder;

    private ResMsg beforeResult;

    private ResMsg AutoResult;

    public ServiceInfo(Object entity, ParamConverter paramConverter, HttpServletRequest request,
                       Order presentOrder, ResMsg beforeResult, ResMsg AutoResult) {
        this.entity = entity;
        this.paramConverter = paramConverter;
        this.request = request;
        this.presentOrder = presentOrder;
        this.beforeResult = beforeResult;
        this.AutoResult = AutoResult;
    }

    public Object getEntity() {
        return entity;
    }

    public void setEntity(Object entity) {
        this.entity = entity;
    }

    public ParamConverter getParamConverter() {
        return paramConverter;
    }

    public void setParamConverter(ParamConverter paramConverter) {
        this.paramConverter = paramConverter;
    }

    public HttpServletRequest getRequest() {
        return request;
    }

    public void setRequest(HttpServletRequest request) {
        this.request = request;
    }

    public Order getPresentOrder() {
        return presentOrder;
    }

    public void setPresentOrder(Order presentOrder) {
        this.presentOrder = presentOrder;
    }

    public ResMsg getBeforeResult() {
        return beforeResult;
    }

    public void setBeforeResult(ResMsg beforeResult) {
        this.beforeResult = beforeResult;
    }

    public ResMsg getAutoResult() {
        return AutoResult;
    }

    public void setAutoResult(ResMsg autoResult) {
        AutoResult = autoResult;
    }

    public Integer getNewId() {
        if (presentOrder.equals(Order.After)) {
            try {
                return Integer.parseInt(this.AutoResult.getData().get("newId").toString());
            } catch (Exception e) {
                return null;
            }
        } else {
            return null;
        }
    }

    public Integer getUserId() {
        return Integer.parseInt(request.getAttribute("userId").toString());
    }

    public String getUserName() {
        return request.getAttribute("userName").toString();
    }

}
